import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
import _useMediaQuery from "@mui/material/useMediaQuery";
import React, { useMemo } from "react";
import classNames from "classnames";
import classes from "./receive.module.less";
import { useReactive } from "ahooks";
import SecondaryLayout from "../../compoents/secondary-layout";
import { useDispatch, useSelector } from "react-redux";
import { QRCodeSVG } from "qrcode.react";
import utilsFilter from "../../utils/filters";
import { useClipboard } from "use-clipboard-copy";
import toast from "../../compoents/toast";
import { matchTheme } from "../../utils";
import { useLocalStorageSetState } from "../../hooks";
import { isDevChain } from "../../config";
import { useTranslation } from "react-i18next";
import { LocalKeyMap } from "../../local";
import ChainSwitch from "../../compoents/chain-switch";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
import { Fragment as _Fragment } from "react/jsx-runtime";
var coinMap = {
    BSC: 1,
    ETHEREUM: 2,
    CONFLUX: 3
};
function Receive() {
    var _useLocalStorageSetState = _sliced_to_array(useLocalStorageSetState(), 2), setLocalStore = _useLocalStorageSetState[1];
    var state = useReactive({
        navList: [
            "BSC",
            "ETHEREUM",
            "CONFLUX"
        ]
    });
    var isPc = _useMediaQuery("(min-width:1280px)");
    var t = useTranslation().t;
    // const services = useServices({
    //   userAddress,
    // });
    var _useSelector = useSelector(function(state) {
        return {
            userInfo: state.app.userInfo,
            theme: state.app.theme,
            chain: state.app.chain
        };
    }), userInfo = _useSelector.userInfo, theme = _useSelector.theme, chain = _useSelector.chain;
    var dispatch = useDispatch();
    var addressMap = useMemo(function() {
        return {
            BSC: {
                test: userInfo.bnbTestAddress,
                main: userInfo.bnbAddress
            },
            ETHEREUM: {
                test: userInfo.ethTestAddress,
                main: userInfo.ethAddress
            },
            CONFLUX: {
                test: userInfo.cfxTestAddress,
                main: userInfo.cfxAddress
            }
        };
    }, [
        userInfo.bnbAddress,
        userInfo.cfxAddress,
        userInfo.ethAddress,
        userInfo.bnbTestAddress,
        userInfo.ethTestAddress,
        userInfo.cfxTestAddress
    ]);
    var bar = useMemo(function() {
        return {
            code: addressMap[chain || "BSC"][isDevChain ? "test" : "main"]
        };
    }, [
        addressMap,
        chain
    ]);
    var copyTip = useMemo(function() {
        return /*#__PURE__*/ _jsx(_Fragment, {
            children: /*#__PURE__*/ _jsxs("div", {
                className: classes.copied,
                children: [
                    /*#__PURE__*/ _jsx("img", {
                        src: require("../../assets/icons/success.svg"),
                        className: classes.successIcon
                    }),
                    t(LocalKeyMap["toast.copy"]),
                    "!"
                ]
            })
        });
    }, []);
    var clipboard = useClipboard({
        onSuccess: function onSuccess() {
            toast({
                content: copyTip,
                duration: 1500,
                centered: true
            });
        },
        onError: function onError() {}
    });
    var copy = function(content) {
        clipboard.copy(content);
    };
    var changeChain = function() {
        var nextChain = Number(coinMap[chain]) + 1 > 3 ? 0 : Number(coinMap[chain]);
        dispatch.app.SET_CHAIN(state.navList[nextChain]);
        setLocalStore({
            chain: state.navList[nextChain]
        });
    };
    return /*#__PURE__*/ _jsx(SecondaryLayout, {
        title: t(LocalKeyMap["receive.title"]),
        children: /*#__PURE__*/ _jsx("div", {
            className: classes.receive,
            children: /*#__PURE__*/ _jsxs("div", {
                className: classes.receive_wrap,
                children: [
                    /*#__PURE__*/ _jsx("div", {
                        className: classes.nav,
                        children: /*#__PURE__*/ _jsx(ChainSwitch, {})
                    }),
                    /*#__PURE__*/ _jsxs("div", {
                        className: classes.content,
                        children: [
                            /*#__PURE__*/ _jsxs("div", {
                                className: classes.qr_box,
                                children: [
                                    /*#__PURE__*/ _jsx("div", {
                                        className: classes.qr_title,
                                        children: t(LocalKeyMap["receive.qr.desc"], {
                                            chain: chain
                                        })
                                    }),
                                    /*#__PURE__*/ _jsx("div", {
                                        className: classNames(classes.qr_code, matchTheme(theme, {
                                            light: classes.qr_code_theme_light,
                                            dark: classes.qr_code_theme_dark
                                        })),
                                        children: /*#__PURE__*/ _jsx(QRCodeSVG, {
                                            value: bar.code,
                                            level: "L",
                                            bgColor: "transparent",
                                            fgColor: "#4F48E2",
                                            imageSettings: {
                                                src: require("../../assets/icons/qrLogo.svg"),
                                                x: undefined,
                                                y: undefined,
                                                width: 35,
                                                height: 35,
                                                excavate: true
                                            }
                                        })
                                    }),
                                    /*#__PURE__*/ _jsxs("div", {
                                        className: classes.address,
                                        children: [
                                            /*#__PURE__*/ _jsx("span", {
                                                children: utilsFilter.stringMethod(bar.code)
                                            }),
                                            /*#__PURE__*/ _jsx("img", {
                                                onClick: function() {
                                                    copy(bar.code);
                                                },
                                                className: classes.copy,
                                                src: require("../../assets/icons/copy.svg")
                                            })
                                        ]
                                    })
                                ]
                            }),
                            /*#__PURE__*/ _jsxs("div", {
                                className: classes.account,
                                children: [
                                    /*#__PURE__*/ _jsx("div", {
                                        className: classes.title,
                                        children: t(LocalKeyMap["receive.address.desc"])
                                    }),
                                    /*#__PURE__*/ _jsx("div", {
                                        className: classes.desc_tip,
                                        children: t(LocalKeyMap["address.tip"])
                                    }),
                                    /*#__PURE__*/ _jsxs("div", {
                                        className: classes.account_box,
                                        children: [
                                            /*#__PURE__*/ _jsxs("div", {
                                                children: [
                                                    "DID: ",
                                                    userInfo.did
                                                ]
                                            }),
                                            /*#__PURE__*/ _jsx("img", {
                                                onClick: function() {
                                                    copy(userInfo.did);
                                                },
                                                className: classes.copy,
                                                src: require("../../assets/icons/copy.svg")
                                            })
                                        ]
                                    })
                                ]
                            })
                        ]
                    })
                ]
            })
        })
    });
}
export default Receive;

 //# sourceMappingURL=index.js.map